//#define __FORCE_TRACE__
//#define __FORCE_DEBUG__
//#define __FORCE_INFO__
#define THIS_FILE "tools\fn_buildingSniperPosBuilder.sqf"
#include <tmf_constants.h>
#include <tmf_macros.h>

TRACE_1("Start",_this);
TMFPROFILERSTART;

private ["_center","_radius","_type","_pos_array","_bldgs","_result","_bldarr"];
DEFAULT_PARAM(_center,0,[]);
DEFAULT_PARAM(_radius,1,200);
_result = [];

if (count _center >= 2) then {
	if (isNil "TMF_BUILDING_SNIPER_INDEXER") then { TMF_BUILDING_SNIPER_INDEXER = [] };
	if (count TMF_BUILDING_SNIPER_INDEXER <= 0) then {
		for "_i" from 0 to (count TMF_BUILDING_POS_INDEXER - 1) do {
			_type = TMF_BUILDING_POS_INDEXER select _i;
			_pos_array = TMF_BUILDING_POS_DETAIL select _i;
			
			if (count _pos_array > TMF_BUILDING_POS_SNIPER) then {
				if (count (_pos_array select TMF_BUILDING_POS_SNIPER) > 0) then {
					TMF_BUILDING_SNIPER_INDEXER set [count TMF_BUILDING_SNIPER_INDEXER, _type];
				};
			};
		};
	};
	_bldgs = nearestObjects [_center, ["House"],_radius];
	if (count _bldgs > 0) then {
		for "_i" from 0 to (count _bldgs - 1) do {
			_bldarr = [(_bldgs select _i),TMF_BUILDING_POS_SNIPER,True, True] call FFUNC(buildingPosArray);
			DEBUG_1("Building Array",ARR_2(_center, _bldarr));
			If (count _bldarr > 0) then {
				_result = [_result, _bldarr] call FFUNC(arrayPushStack);
			};
		};
	};
} else {
	ERROR_1("Invalid input",_this);
};
TRACE("End");
TMFPROFILERSTOP;
_result